package org.ChrisRiffle.Acme.BoundingBox.controlers;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;

/**
 * Intended to verify valid data entry on the formatted text fields for the
 * points
 * 
 * @author RIF
 * 
 */
public class TxtFieldInputVerifier extends InputVerifier {


	@Override
	public boolean shouldYieldFocus(JComponent input) {
	
		boolean bYield =  super.shouldYieldFocus(input);
		
		if(!bYield){
			((JFormattedTextField)input).selectAll();
		}
		
		return bYield;
	}
	
	
	@Override
	public boolean verify(JComponent input) {
		
		String txt = ((JFormattedTextField)input).getText();
		
		float value = 0f;
				
		
		try{
			value = Float.parseFloat(txt);
			
		}catch (Exception e) {

			return false;
		}
		
		
		if(value < 0){
			
			return false;
		}
		
		
		return true;
	}
	
}
